﻿@model ChangePasswordModel
@{
    Layout = "~/Views/Shared/_ColumnsTwoLeft.cshtml";

    //title
    Html.AddTitleParts(T("PageTitle.Account").Text);
}
@section left
{
    @Html.Partial("MyAccountNavigation", Model.NavigationModel, new ViewDataDictionary())
}

@Html.AntiForgeryToken()
<!--密码修改Start-->
<div id="pwsreset">
    <div class="rightpane">
        <div class="title01">修改密码</div>
        <div class="formcontent">
            <div class="pwdrecovery">
                <div class="item">
                    <span class="label">原密码： </span>
                    <div class="fl item-ifo">
                        <div class="o-intelligent-regName">
                            <input id="txt_oldpassword" class="text01 password input_true" value="" tabindex="1" autocomplete="off" maxlength="20" type="password">
                        </div>
                    </div>
                </div>
                <div class="item">
                    <span class="label">新密码 </span>
                    <div class="fl item-ifo">
                        <div class="o-intelligent-regName">
                            <input id="txt_newpwd" class="text01 password input_true" value="" tabindex="1" autocomplete="off" maxlength="20" type="password">
                        </div>
                    </div>
                </div>
                <div class="item">
                    <span class="label">确认密码： </span>
                    <div class="fl item-ifo">
                        <div class="o-intelligent-regName">
                            <input id="txt_pwdagain" class="text01 password input_true" value="" tabindex="1" autocomplete="off" maxlength="20" type="password">
                        </div>
                    </div>
                </div>
                <div class="item">
                    <span class="label">&nbsp;</span><input id="resetpwd" type="button" class="input_submit" value="确认修改" />
                </div>

            </div>
        </div>
    </div>
</div>
<!--密码修改End-->
<script>
    $(function () {
        var token = $('[name=__RequestVerificationToken]').val();

        $("#resetpwd").click(function () {
            var oldpassword;
            var newpwd;
            var pwdagain;
            //得到各个文本框的值
            oldpassword = $.trim($("#txt_oldpassword").val());
            newpwd = $.trim($("#txt_newpwd").val());
            pwdagain = $.trim($("#txt_pwdagain").val());

            if (oldpassword == "") {
                alert("请输入原密码");
                return false;
            }
            if (newpwd == "") {
                alert("请输入新密码");
                return false;
            }
            if (pwdagain == "") {
                alert("请输入确认密码");
                return false;
            }
            if (newpwd != pwdagain) {
                alert("两次输入密码不一致");
                return false;
            }
            var headers = {};
            //防伪标记放入headers
            //也可以将防伪标记放入data
            headers["__RequestVerificationToken"] = token;
            //验证完成后执行的事件
            $.ajax({
                type: 'POST',
                async: false,
                headers: headers,
                url: '/Member/ChangePassword/',
                data: {
                    oldpassword: $.trim($("#txt_oldpassword").val()),
                    newpassword: $.trim($("#txt_newpwd").val()),
                    confirmnewpassword: $.trim($("#txt_pwdagain").val())
                },
                success: function (data) {
                    if (data.Result) {
                        alert("密码修改成功");
                        window.location.href = "/Logout/";
                    } else {
                        if (data.Code == '100') {
                            alert("账号已经退出或超时!");
                            window.location.href = "/Login/";
                        }
                        else {
                            alert(data.Message);
                        }

                    }
                }
            });

        });
    });
</script>